#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    const int INF=INT_MAX/2;
    int findTheCity(int n, vector<vector<int>>& edges, int d) {
        vector<vector<int>> f(n,vector<int>(n,INF));
        for(int i=0;i<n;i++) f[i][i]=0;
        for(auto& e:edges)
        {
            f[e[0]][e[1]]=e[2];
            f[e[1]][e[0]]=e[2];
        }

        for(int k=0;k<n;k++)
        {
            for(int i=0;i<n;i++)
            {
                if(f[i][k]>=INF) continue;
                for(int j=0;j<n;j++)
                {
                    f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
                }
            }
        }
        vector<int> vec(n,0);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(f[i][j]<=d&&i!=j) vec[i]++;
            }
        }
        int idx=INT_MIN;
        int count=INT_MAX;
        for(int i=0;i<n;i++)
        {
            int v=vec[i];
            if(count==v)
            {
                if(idx<i)
                {
                    idx=i;
                }
            }
            else if(count>v)
            {
                idx=i;
                count=v;
            }
            

        }
        return idx;
    }
};

int main()
{
    vector<vector<int>> vec={{0,1,2},{0,4,8},{1,2,3},{1,4,2},{2,3,1},{3,4,1}};
    Solution so;
    so.findTheCity(5,vec,2);
    return 0;
}